<?php namespace app\admin\controller;

use system\model\Config;
use system\model\Keyword;

class Message{

//    构造函数
    public function __construct()
    {
        User::isLogin();
    }




//    消息管理列表
    public function lists(){
        $module = Request::get('m');
        $data = Db::table('keywords')->where('module',$module)->paginate(10);
        View::with('data',$data);
        return View::make();
    }

//    添加关键字
    public function post(){
        $module = Request::get('m');
        $class = 'module\\' . $module .'\Message';
//        实例化类
        $obj = new $class;
        if(IS_POST){
//            关键字表
            $keyword = new Keyword;
            $keyword['keyword'] = Request::post( 'keyword' );
            $keyword['module'] = $module;
            $kid = $keyword->save();
            $obj->submit($kid);
            message('保存成功',u('lists',['m'=>$module]),'success');
        }
        View::with('messageFile',$obj->display());

        return View::make();
    }

//    系统消息
    public function system(){
        if(IS_POST){
            $config = new Config();
            $config['id'] = 1;
            $config['default_message'] = Request::post('content');
            $config->save();
            message( '保存成功', 'system', 'success' );
        }
        return View::make();
    }




}